<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />





  <link rel="alternate" href="/atom.xml" title="liujinlongxa的技术博客" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="RAC简介RAC要解决的问题是传统ios中事件，通知，回调的机制十分的繁琐。
常规用法target-action
RAC可以替代一般的target-action操作，例如监测textField的文字的改变，不是用RAC的写法

12345678910111213141516171819- (void)viewDidLoad &amp;#123;    [super viewDidLoad];    UIT">
<meta property="og:type" content="article">
<meta property="og:title" content="RAC学习笔记">
<meta property="og:url" content="http://yoursite.com/2015/12/20/RAC学习笔记/index.html">
<meta property="og:site_name" content="liujinlongxa的技术博客">
<meta property="og:description" content="RAC简介RAC要解决的问题是传统ios中事件，通知，回调的机制十分的繁琐。
常规用法target-action
RAC可以替代一般的target-action操作，例如监测textField的文字的改变，不是用RAC的写法

12345678910111213141516171819- (void)viewDidLoad &amp;#123;    [super viewDidLoad];    UIT">
<meta property="og:updated_time" content="2016-07-01T12:43:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="RAC学习笔记">
<meta name="twitter:description" content="RAC简介RAC要解决的问题是传统ios中事件，通知，回调的机制十分的繁琐。
常规用法target-action
RAC可以替代一般的target-action操作，例如监测textField的文字的改变，不是用RAC的写法

12345678910111213141516171819- (void)viewDidLoad &amp;#123;    [super viewDidLoad];    UIT">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://yoursite.com/2015/12/20/RAC学习笔记/"/>

  <title> RAC学习笔记 | liujinlongxa的技术博客 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">liujinlongxa的技术博客</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle"></p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                RAC学习笔记
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-12-20T00:00:00+08:00" content="2015-12-20">
              2015-12-20
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/iOS开发/" itemprop="url" rel="index">
                    <span itemprop="name">iOS开发</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2015/12/20/RAC学习笔记/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2015/12/20/RAC学习笔记/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="RAC简介"><a href="#RAC简介" class="headerlink" title="RAC简介"></a>RAC简介</h2><p>RAC要解决的问题是传统ios中事件，通知，回调的机制十分的繁琐。</p>
<h2 id="常规用法"><a href="#常规用法" class="headerlink" title="常规用法"></a>常规用法</h2><h3 id="target-action"><a href="#target-action" class="headerlink" title="target-action"></a>target-action</h3><ul>
<li>RAC可以替代一般的target-action操作，例如监测textField的文字的改变，不是用RAC的写法</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</div><div class="line">    [<span class="keyword">super</span> viewDidLoad];</div><div class="line"></div><div class="line">    <span class="built_in">UITextField</span> *text = (&#123;</div><div class="line">        <span class="built_in">UITextField</span> *text = [[<span class="built_in">UITextField</span> alloc] init];</div><div class="line">        [<span class="keyword">self</span>.view addSubview:text];</div><div class="line">        [text mas_makeConstraints:^(MASConstraintMaker *make) &#123;</div><div class="line">            make.center.equalTo(<span class="keyword">self</span>.view);</div><div class="line">            make.size.mas_equalTo(<span class="built_in">CGSizeMake</span>(<span class="number">200</span>, <span class="number">40</span>));</div><div class="line">        &#125;];</div><div class="line">        text.backgroundColor = [<span class="built_in">UIColor</span> redColor];</div><div class="line">        [text addTarget:<span class="keyword">self</span> action:<span class="keyword">@selector</span>(textDidChange:) forControlEvents:<span class="built_in">UIControlEventEditingChanged</span>];</div><div class="line">        text;</div><div class="line">    &#125;);</div><div class="line">&#125;</div><div class="line"></div><div class="line">- (<span class="keyword">void</span>)textDidChange:(<span class="built_in">UITextField</span> *)sender &#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"did change: %@"</span>, sender);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li>使用RAC的写法：<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</div><div class="line">    [<span class="keyword">super</span> viewDidLoad];</div><div class="line"></div><div class="line">    <span class="built_in">UITextField</span> *text = (&#123;</div><div class="line">        <span class="built_in">UITextField</span> *text = [[<span class="built_in">UITextField</span> alloc] init];</div><div class="line">        [<span class="keyword">self</span>.view addSubview:text];</div><div class="line">        [text mas_makeConstraints:^(MASConstraintMaker *make) &#123;</div><div class="line">            make.center.equalTo(<span class="keyword">self</span>.view);</div><div class="line">            make.size.mas_equalTo(<span class="built_in">CGSizeMake</span>(<span class="number">200</span>, <span class="number">40</span>));</div><div class="line">        &#125;];</div><div class="line">        text.backgroundColor = [<span class="built_in">UIColor</span> redColor];</div><div class="line"></div><div class="line">        [[text rac_signalForControlEvents:<span class="built_in">UIControlEventEditingChanged</span>] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">            <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">        &#125;];</div><div class="line"></div><div class="line">        <span class="comment">// 或者</span></div><div class="line">        <span class="comment">//[text.rac_textSignal subscribeNext:^(id x) &#123;</span></div><div class="line">        <span class="comment">//    NSLog(@"%@", x);</span></div><div class="line">        <span class="comment">//&#125;];</span></div><div class="line"></div><div class="line">        text;</div><div class="line">    &#125;);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="手势中使用RAC"><a href="#手势中使用RAC" class="headerlink" title="手势中使用RAC"></a>手势中使用RAC</h3><ul>
<li>RAC可以替换手势的方法，代码如下</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</div><div class="line">    [<span class="keyword">super</span> viewDidLoad];</div><div class="line"></div><div class="line">    <span class="keyword">self</span>.view.userInteractionEnabled = <span class="literal">YES</span>;</div><div class="line">    <span class="built_in">UITapGestureRecognizer</span> *tap = [[<span class="built_in">UITapGestureRecognizer</span> alloc] init];</div><div class="line">    [[tap rac_gestureSignal] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">    &#125;];</div><div class="line">    [<span class="keyword">self</span>.view addGestureRecognizer:tap];</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="通知"><a href="#通知" class="headerlink" title="通知"></a>通知</h3><ul>
<li>RAC可以代替通知，并且RAC的通知不用移出</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</div><div class="line">    [<span class="keyword">super</span> viewDidLoad];</div><div class="line">    [[[<span class="built_in">NSNotificationCenter</span> defaultCenter] rac_addObserverForName:<span class="built_in">UIApplicationDidBecomeActiveNotification</span> object:<span class="literal">nil</span>] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">    &#125;];</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="定制器"><a href="#定制器" class="headerlink" title="定制器"></a>定制器</h3><ul>
<li>RAC可以代替定时器</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</div><div class="line">    [<span class="keyword">super</span> viewDidLoad];</div><div class="line"></div><div class="line">    <span class="comment">// 延迟2秒执行</span></div><div class="line">    [[RACScheduler mainThreadScheduler] afterDelay:<span class="number">2.0</span> schedule:^&#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"haha"</span>);</div><div class="line">    &#125;];</div><div class="line"></div><div class="line">    <span class="comment">// interval为间隔事件，scheduler为在那个线程上执行，leeway为多久之后开始执行。</span></div><div class="line">    [[RACSignal interval:<span class="number">2.0</span> onScheduler:[RACScheduler mainThreadScheduler] withLeeway:<span class="number">5.0</span>] subscribeNext:^(<span class="built_in">NSDate</span> x) &#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">    &#125;];</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="代理"><a href="#代理" class="headerlink" title="代理"></a>代理</h3><ul>
<li>RAC可以替换代理，但仅限没有返回值的代理</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">ViewController</span> ()&lt;<span class="title">UITableViewDelegate</span>&gt;</span></div><div class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">UIAlertView</span> *alertView;</div><div class="line"></div><div class="line"><span class="keyword">@end</span></div><div class="line"></div><div class="line"><span class="class"><span class="keyword">@implementation</span> <span class="title">ViewController</span></span></div><div class="line"></div><div class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</div><div class="line">    [<span class="keyword">super</span> viewDidLoad];</div><div class="line"></div><div class="line">    <span class="keyword">self</span>.alertView = [[<span class="built_in">UIAlertView</span> alloc] initWithTitle:<span class="string">@"RAC"</span> message:<span class="string">@"test"</span> delegate:<span class="keyword">self</span> cancelButtonTitle:<span class="string">@"OK"</span> otherButtonTitles: <span class="literal">nil</span>];</div><div class="line">    [[<span class="keyword">self</span> rac_signalForSelector:<span class="keyword">@selector</span>(alertView:clickedButtonAtIndex:) fromProtocol:<span class="class"><span class="keyword">@protocol</span>(<span class="title">UIAlertViewDelegate</span>)]<span class="title">subscribeNext</span>:^(<span class="title">id</span> <span class="title">x</span>) </span>&#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>,x);</div><div class="line">    &#125;];</div><div class="line">    <span class="comment">// 或者</span></div><div class="line">    <span class="comment">// [[self.alertView rac_buttonClickedSignal] subscribeNext:^(id x) &#123;</span></div><div class="line">    <span class="comment">//     NSLog(@"%@", x);</span></div><div class="line">    <span class="comment">// &#125;];</span></div><div class="line"></div><div class="line">    [<span class="keyword">self</span>.alertView show];</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="keyword">@end</span></div></pre></td></tr></table></figure>
<h3 id="KVO"><a href="#KVO" class="headerlink" title="KVO"></a>KVO</h3><ul>
<li>RAC可以替换KVO</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">ViewController</span> ()</span></div><div class="line"></div><div class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">assign</span>) <span class="built_in">NSInteger</span> index;</div><div class="line"><span class="keyword">@end</span></div><div class="line"></div><div class="line"><span class="class"><span class="keyword">@implementation</span> <span class="title">ViewController</span></span></div><div class="line"></div><div class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</div><div class="line">    [<span class="keyword">super</span> viewDidLoad];</div><div class="line"></div><div class="line">    [RACObserve(<span class="keyword">self</span>, index) subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">    &#125;];</div><div class="line"></div><div class="line">&#125;</div><div class="line"></div><div class="line">- (<span class="keyword">void</span>)touchesBegan:(<span class="built_in">NSSet</span>&lt;<span class="built_in">UITouch</span> *&gt; *)touches withEvent:(<span class="built_in">UIEvent</span> *)event &#123;</div><div class="line">    <span class="keyword">self</span>.index++;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="keyword">@end</span></div></pre></td></tr></table></figure>
<h2 id="高级用法"><a href="#高级用法" class="headerlink" title="高级用法"></a>高级用法</h2><h3 id="创建信号"><a href="#创建信号" class="headerlink" title="创建信号"></a>创建信号</h3><figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div></pre></td><td class="code"><pre><div class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</div><div class="line">    [<span class="keyword">super</span> viewDidLoad];</div><div class="line"></div><div class="line">    RACSignal *signal = [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">        <span class="built_in">NSURLRequest</span> *req = [<span class="built_in">NSURLRequest</span> requestWithURL:[<span class="built_in">NSURL</span> URLWithString:<span class="string">@"http://www.baidu.com"</span>]];</div><div class="line">        [<span class="built_in">NSURLConnection</span> sendAsynchronousRequest:req queue:[<span class="built_in">NSOperationQueue</span> mainQueue] completionHandler:^(<span class="built_in">NSURLResponse</span> * _Nullable response, <span class="built_in">NSData</span> * _Nullable data, <span class="built_in">NSError</span> * _Nullable connectionError) &#123;</div><div class="line">            <span class="keyword">if</span> (connectionError) &#123;</div><div class="line">                <span class="comment">// 请求失败</span></div><div class="line">                [subscriber sendError:connectionError];</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">else</span> &#123;</div><div class="line">                <span class="comment">// 请求成功</span></div><div class="line">                [subscriber sendNext:data];</div><div class="line">            &#125;</div><div class="line">            [subscriber sendCompleted];</div><div class="line">        &#125;];</div><div class="line">        <span class="keyword">return</span> [RACDisposable disposableWithBlock:^&#123;</div><div class="line">            <span class="comment">// 取消订阅</span></div><div class="line">            <span class="built_in">NSLog</span>(<span class="string">@"cancel"</span>);</div><div class="line">        &#125;];</div><div class="line">    &#125;];</div><div class="line"></div><div class="line">    RACDisposable *disposable = [signal subscribeNext:^(<span class="built_in">NSData</span> *responseData) &#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, responseData);</div><div class="line">    &#125; error:^(<span class="built_in">NSError</span> *error) &#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, error);</div><div class="line">    &#125; completed:^&#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"completed"</span>);</div><div class="line">    &#125;];</div><div class="line"></div><div class="line">    <span class="comment">// 订阅完就取消订阅，这样就不会执行订阅block了</span></div><div class="line">    [disposable dispose];</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="信号处理"><a href="#信号处理" class="headerlink" title="信号处理"></a>信号处理</h3><ul>
<li>map:映射</li>
<li>filter:过滤</li>
<li>delay:延时</li>
<li>startWith:在接收到信号前，先接收到一个信号</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</div><div class="line">    [<span class="keyword">super</span> viewDidLoad];</div><div class="line"></div><div class="line">    <span class="built_in">UITextField</span> *textField = (&#123;</div><div class="line">        <span class="built_in">UITextField</span> *view = [[<span class="built_in">UITextField</span> alloc] init];</div><div class="line">        [<span class="keyword">self</span>.view addSubview:view];</div><div class="line">        [view mas_makeConstraints:^(MASConstraintMaker *make) &#123;</div><div class="line">            make.center.equalTo(<span class="keyword">self</span>.view);</div><div class="line">            make.size.mas_equalTo(<span class="built_in">CGSizeMake</span>(<span class="number">200</span>, <span class="number">40</span>));</div><div class="line">        &#125;];</div><div class="line">        view.backgroundColor = [<span class="built_in">UIColor</span> redColor];</div><div class="line">        view;</div><div class="line">    &#125;);</div><div class="line"></div><div class="line">    [[[[[[textField rac_textSignal] map:^<span class="keyword">id</span>(<span class="keyword">id</span> value) &#123;</div><div class="line">        <span class="built_in">NSString</span> *str = (<span class="built_in">NSString</span> *)value;</div><div class="line">        <span class="keyword">return</span> @([str length]);</div><div class="line">    &#125;] filter:^<span class="built_in">BOOL</span>(<span class="keyword">id</span> value) &#123;</div><div class="line">        <span class="keyword">return</span> [value integerValue] &gt; <span class="number">3</span>;</div><div class="line">    &#125;] delay:<span class="number">2</span>] startWith:<span class="string">@"haha"</span>] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">    &#125;];</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li>timeout:超时</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">RACSignal *signal = [[RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line"></div><div class="line">    [[RACScheduler mainThreadScheduler] afterDelay:<span class="number">1.0</span> schedule:^&#123;</div><div class="line">        [subscriber sendNext:<span class="string">@"hello"</span>];</div><div class="line">        [subscriber sendCompleted];</div><div class="line">    &#125;];</div><div class="line">    <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line"></div><div class="line">&#125;] timeout:<span class="number">2.0</span> onScheduler:[RACScheduler mainThreadScheduler]]; <span class="comment">// 如果请求没有在2秒内完成，则请求超时，会调用errorBlock</span></div><div class="line"></div><div class="line">[signal subscribeNext:^(<span class="built_in">NSData</span> *responseData) &#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, responseData);</div><div class="line">&#125; error:^(<span class="built_in">NSError</span> *error) &#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, error);</div><div class="line">&#125; completed:^&#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"completed"</span>);</div><div class="line">&#125;];</div></pre></td></tr></table></figure>
<ul>
<li>take:接收到多次信号，但只处理前几次信号</li>
<li>takeLast:只处理最后几次信号</li>
<li>skip:忽略几次</li>
<li>takeUntilBlock:返回YES可以表示不接收，返回NO表示接收该信号，与filter类似</li>
<li>takeWhileBlock:当返回一次YES后，就停止接收所有信号</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">RACSignal *signal = [[RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line"></div><div class="line">    [subscriber sendNext:<span class="string">@"hello1"</span>];</div><div class="line">    [subscriber sendNext:<span class="string">@"hello2"</span>];</div><div class="line">    [subscriber sendNext:<span class="string">@"hello3"</span>];</div><div class="line">    [subscriber sendNext:<span class="string">@"hello4"</span>];</div><div class="line">    [subscriber sendNext:<span class="string">@"hello5"</span>];</div><div class="line">    [subscriber sendCompleted];</div><div class="line">    <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line"></div><div class="line">&#125;] takeLast:<span class="number">2</span>];</div><div class="line"></div><div class="line">[signal subscribeNext:^(<span class="keyword">id</span> value) &#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, value);</div><div class="line">&#125;];</div></pre></td></tr></table></figure>
<ul>
<li>throttle:节流，可以规定两个信号的间隔时间必须大于某个值</li>
<li>distinctUntilChanged:直到订阅的内容发生变化才会处理信号</li>
<li>ignore:忽略某些信号值</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">UITextField</span> *textField = (&#123;</div><div class="line">    <span class="built_in">UITextField</span> *view = [[<span class="built_in">UITextField</span> alloc] init];</div><div class="line">    [<span class="keyword">self</span>.view addSubview:view];</div><div class="line">    [view mas_makeConstraints:^(MASConstraintMaker *make) &#123;</div><div class="line">        make.center.equalTo(<span class="keyword">self</span>.view);</div><div class="line">        make.size.mas_equalTo(<span class="built_in">CGSizeMake</span>(<span class="number">200</span>, <span class="number">40</span>));</div><div class="line">    &#125;];</div><div class="line">    view.backgroundColor = [<span class="built_in">UIColor</span> redColor];</div><div class="line">    view;</div><div class="line">&#125;);</div><div class="line"></div><div class="line"><span class="comment">// 如果文字的改变速度过快，则不处理，两次信号间隔时间必须大于0.3秒</span></div><div class="line">[[[[[textField rac_textSignal] throttle:<span class="number">0.3</span>] distinctUntilChanged] ignore:<span class="string">@""</span>] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">&#125;];</div></pre></td></tr></table></figure>
<ul>
<li>flattenMap:订阅的值为一个信号，将该信号转为订阅具体的值</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">UITextField</span> *textField = (&#123;</div><div class="line">    <span class="built_in">UITextField</span> *view = [[<span class="built_in">UITextField</span> alloc] init];</div><div class="line">    [<span class="keyword">self</span>.view addSubview:view];</div><div class="line">    [view mas_makeConstraints:^(MASConstraintMaker *make) &#123;</div><div class="line">        make.center.equalTo(<span class="keyword">self</span>.view);</div><div class="line">        make.size.mas_equalTo(<span class="built_in">CGSizeMake</span>(<span class="number">200</span>, <span class="number">40</span>));</div><div class="line">    &#125;];</div><div class="line">    view.backgroundColor = [<span class="built_in">UIColor</span> redColor];</div><div class="line">    view;</div><div class="line">&#125;);</div><div class="line"></div><div class="line">[[[textField.rac_textSignal throttle:<span class="number">0.3</span>] flattenMap:^<span class="keyword">id</span>(<span class="keyword">id</span> value) &#123;</div><div class="line">    <span class="keyword">return</span> [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">        [subscriber sendNext:<span class="string">@"aaa"</span>];</div><div class="line">        [subscriber sendCompleted];</div><div class="line">        <span class="keyword">return</span> [RACDisposable disposableWithBlock:^&#123;</div><div class="line"></div><div class="line">        &#125;];</div><div class="line">    &#125;];</div><div class="line">&#125;] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">&#125;];</div></pre></td></tr></table></figure>
<ul>
<li>repeat:重复发送某个信号</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">RACSignal *signal = [[RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">        [subscriber sendNext:[<span class="built_in">NSDate</span> date]];</div><div class="line">        [subscriber sendCompleted];</div><div class="line">        <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">    &#125;] repeat];</div><div class="line"></div><div class="line">    [signal subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">    &#125;];</div></pre></td></tr></table></figure>
<ul>
<li>merge:同时订阅两个信号源，无论哪个发出信号，都会执行</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<span class="number">2.0</span> * <span class="built_in">NSEC_PER_SEC</span>)), dispatch_get_main_queue(), ^&#123;</div><div class="line">          [subscriber sendNext:<span class="string">@"1"</span>];</div><div class="line">          [subscriber sendCompleted];</div><div class="line">      &#125;);</div><div class="line">      <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">  &#125;];</div><div class="line"></div><div class="line">  RACSignal *signalB = [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<span class="number">3.0</span> * <span class="built_in">NSEC_PER_SEC</span>)), dispatch_get_main_queue(), ^&#123;</div><div class="line">          [subscriber sendNext:<span class="string">@"2"</span>];</div><div class="line">          [subscriber sendCompleted];</div><div class="line">      &#125;);</div><div class="line">      <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">  &#125;];</div><div class="line"></div><div class="line">  [[signalA merge:signalB] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">      <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">  &#125;];</div></pre></td></tr></table></figure>
<ul>
<li>combineLatest:reduce:这是一个RACSignal的类方法，表示同时聚合多个信号</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<span class="number">2.0</span> * <span class="built_in">NSEC_PER_SEC</span>)), dispatch_get_main_queue(), ^&#123;</div><div class="line">            [subscriber sendNext:<span class="string">@"1"</span>];</div><div class="line">            [subscriber sendCompleted];</div><div class="line">        &#125;);</div><div class="line">        <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">    &#125;];</div><div class="line"></div><div class="line">    RACSignal *signalB = [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<span class="number">3.0</span> * <span class="built_in">NSEC_PER_SEC</span>)), dispatch_get_main_queue(), ^&#123;</div><div class="line">            [subscriber sendNext:<span class="string">@"2"</span>];</div><div class="line">            [subscriber sendCompleted];</div><div class="line">        &#125;);</div><div class="line">        <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">    &#125;];</div><div class="line"></div><div class="line">    [[RACSignal combineLatest:@[signalA, signalB] reduce:^<span class="keyword">id</span>(<span class="built_in">NSString</span> *s1, <span class="built_in">NSString</span> *s2)&#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"s1=%@, s2=%@"</span>, s1, s2);</div><div class="line">        <span class="keyword">return</span> [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@%@"</span>, s1, s2];</div><div class="line">    &#125;] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">        <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">    &#125;];</div></pre></td></tr></table></figure>
<ul>
<li>concat:先订阅信号A，A执行完成后再订阅信号B</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<span class="number">2.0</span> * <span class="built_in">NSEC_PER_SEC</span>)), dispatch_get_main_queue(), ^&#123;</div><div class="line">        [subscriber sendNext:<span class="string">@"1"</span>];</div><div class="line">        [subscriber sendCompleted];</div><div class="line">    &#125;);</div><div class="line">    <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">&#125;];</div><div class="line"></div><div class="line">RACSignal *signalB = [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<span class="number">2.0</span> * <span class="built_in">NSEC_PER_SEC</span>)), dispatch_get_main_queue(), ^&#123;</div><div class="line">        [subscriber sendNext:<span class="string">@"2"</span>];</div><div class="line">        [subscriber sendCompleted];</div><div class="line">    &#125;);</div><div class="line">    <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">&#125;];</div><div class="line"></div><div class="line"><span class="comment">// 先订阅A，A执行完成后，再执行B，如果A失败了，不会再执行B</span></div><div class="line">[[signalA concat:signalB] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">&#125;];</div></pre></td></tr></table></figure>
<ul>
<li>zipWith:两个信号都发出后，再执行，也可以使用combineLatest:</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<span class="number">2.0</span> * <span class="built_in">NSEC_PER_SEC</span>)), dispatch_get_main_queue(), ^&#123;</div><div class="line">        [subscriber sendNext:<span class="string">@"1"</span>];</div><div class="line">        [subscriber sendCompleted];</div><div class="line">    &#125;);</div><div class="line">    <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">&#125;];</div><div class="line"></div><div class="line">RACSignal *signalB = [RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<span class="number">3.0</span> * <span class="built_in">NSEC_PER_SEC</span>)), dispatch_get_main_queue(), ^&#123;</div><div class="line">        [subscriber sendNext:<span class="string">@"2"</span>];</div><div class="line">        [subscriber sendCompleted];</div><div class="line">    &#125;);</div><div class="line">    <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">&#125;];</div><div class="line"></div><div class="line">[[signalA zipWith:signalB] subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">    <span class="comment">// x是一个RACTuple，包含了signalA和signalB的值</span></div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">&#125;];</div></pre></td></tr></table></figure>
<h3 id="RAC的坑"><a href="#RAC的坑" class="headerlink" title="RAC的坑"></a>RAC的坑</h3><ul>
<li>side effect: 一个信号源被多个订阅者订阅，每个订阅者收到的信号可能不一样。解决方法：使用reply</li>
</ul>
<figure class="highlight objectivec"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">RACSignal *signalA = [[RACSignal createSignal:^RACDisposable *(<span class="keyword">id</span>&lt;RACSubscriber&gt; subscriber) &#123;</div><div class="line">    <span class="keyword">static</span> <span class="keyword">int</span> i = <span class="number">0</span>;</div><div class="line">    i++;</div><div class="line">    [subscriber sendNext:@(i)];</div><div class="line">    [subscriber sendCompleted];</div><div class="line">    <span class="keyword">return</span> <span class="literal">nil</span>;</div><div class="line">&#125;] replay];</div><div class="line"></div><div class="line">[signalA subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">&#125;];</div><div class="line"></div><div class="line">[signalA subscribeNext:^(<span class="keyword">id</span> x) &#123;</div><div class="line">    <span class="built_in">NSLog</span>(<span class="string">@"%@"</span>, x);</div><div class="line">&#125;];</div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        
      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/12/13/CoreAnimation编程指南学习笔记(2)/" rel="next" title="CoreAnimation编程指南学习笔记(2)">
                <i class="fa fa-chevron-left"></i> CoreAnimation编程指南学习笔记(2)
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/12/27/《ios核心动画高级技巧》阅读笔记(1)/" rel="prev" title="《ios核心动画高级技巧》阅读笔记(1)">
                《ios核心动画高级技巧》阅读笔记(1) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2015/12/20/RAC学习笔记/"
           data-title="RAC学习笔记" data-url="http://yoursite.com/2015/12/20/RAC学习笔记/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/smallhead.png"
               alt="liujinlongxa" />
          <p class="site-author-name" itemprop="name">liujinlongxa</p>
          <p class="site-description motion-element" itemprop="description">生命永不息，Coding永不止</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">31</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/liujinlongxa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/JaylonLiu" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/u/1523828165/home" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.douban.com/people/2470188/" target="_blank" title="豆瓣">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  豆瓣
                </a>
              </span>
            
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#RAC简介"><span class="nav-number">1.</span> <span class="nav-text">RAC简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#常规用法"><span class="nav-number">2.</span> <span class="nav-text">常规用法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#target-action"><span class="nav-number">2.1.</span> <span class="nav-text">target-action</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#手势中使用RAC"><span class="nav-number">2.2.</span> <span class="nav-text">手势中使用RAC</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#通知"><span class="nav-number">2.3.</span> <span class="nav-text">通知</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#定制器"><span class="nav-number">2.4.</span> <span class="nav-text">定制器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代理"><span class="nav-number">2.5.</span> <span class="nav-text">代理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#KVO"><span class="nav-number">2.6.</span> <span class="nav-text">KVO</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#高级用法"><span class="nav-number">3.</span> <span class="nav-text">高级用法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建信号"><span class="nav-number">3.1.</span> <span class="nav-text">创建信号</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#信号处理"><span class="nav-number">3.2.</span> <span class="nav-text">信号处理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#RAC的坑"><span class="nav-number">3.3.</span> <span class="nav-text">RAC的坑</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">liujinlongxa</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"liujinlongxa"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
  






  
  
  

  

  

</body>
</html>
